import type { ResponseData, ResponsePaginationData } from '@/utils/request';
import type { RequestData } from '@ant-design/pro-table';
import { request } from 'umi';
import type { addItem, chargeItem, chargeTableList, QueryParams, updateItem } from './types';

//获取收费规则列表
export async function getChargeTable(params: QueryParams): Promise<RequestData<chargeTableList>> {
  return await request('/charge/scheme/page', {
    params: {
      ...params,
      page: params.current,
      tenantId: params.tenant && params.tenant?.id,
      schemeId: params.id,
      schemeName: params.name,
    },
  });
}

//查询单个数据
export async function getChargeDetail(id: string) {
  return await request(`/charge/scheme/${id}/detail`);
}

//添加收费规则
export async function addChargeItem(
  params: addItem,
): Promise<ResponsePaginationData<ResponseData<addItem>>> {
  return await request('/charge/scheme/create', {
    method: 'POST',
    data: params,
  });
}

//更新收费规则
export async function updateChargeItem(params: updateItem): Promise<ResponseData<updateItem>> {
  return await request('/charge/scheme/update', {
    method: 'POST',
    data: params,
  });
}

//删除收费规则
export async function deleteCharge(id: string): Promise<ResponseData<chargeItem>> {
  return await request(`/charge/scheme/${id}`, {
    method: 'DELETE',
  });
}

//获取收费规则列表
export async function optionsSchemeItem(params: {
  text: string;
  tenantId: number;
  page: number;
  pageSize: number;
}): Promise<ResponseData<any>> {
  return await request('/charge/scheme/get_scheme_options', {
    params: {
      ...params,
    },
  });
}
